//
// Created by liushuai on 18-7-16.
//

#include "Time.hpp"
#include <iostream>
Time::Time() {
    hours = 0;
    minutes = 0;
}
Time::Time(int h, int m) {
    hours = h;
    minutes = m;
}
void Time::addhour(int h) {
    hours += h;
}
void Time::addmin(int m) {
    minutes += m;
}
void Time::reset(int h, int m) {
    hours = h;
    minutes = m;
}
Time Time::operator+(const Time &t) const {
    Time sum;
    sum.minutes = minutes + t.minutes;
    sum.hours = hours + t.hours+sum.minutes/60;
    sum.minutes %= 60;
    return sum;
}
Time Time::operator-(const Time &t) const {
    Time sub;
    int total1 = hours*60+minutes;
    int total2 = t.hours*60+t.minutes;
    int sub_int = total1-total2;
    sub.hours = sub_int/60;
    sub.minutes = sub_int%60;
    return sub;
}
Time Time::operator*(double x) const {
    int total;
    Time mul;
    total = x*hours*60+minutes*x;
    mul.hours = total/60;
    mul.minutes = total%60;
    return mul;
}

std::ostream & operator<<(std::ostream & os, const Time & t) {
    os<<t.hours<<" hours, "<<t.minutes<<" minutes ";
    return os;
}